/**
 * 
 */
package com.feonix.nio.test.scatterandgatter;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @CopyRight (c)1993-2017
 * @Project common_practice
 * @Comments 请输入该类的描述
 * @NameSpace com.feonix.nio.test.scatterandgatter
 * @Author Feonixzw
 * @CreateDate 2018年3月12日
 */
public class TransferFromTo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	public static void method1() {
		RandomAccessFile transferFromFile = null;
		RandomAccessFile transferToFile = null;
		try {
			transferFromFile = new RandomAccessFile(
					"D:\\workspace3\\common_practice\\src\\main\\java\\com\\feonix\\nio\\test\\scatterandgatter\\transferfrom.txt",
					"rw");
			FileChannel fromFC = transferFromFile.getChannel();
			transferToFile = new RandomAccessFile(
					"D:\\workspace3\\common_practice\\src\\main\\java\\com\\feonix\\nio\\test\\scatterandgatter\\transferto.txt",
					"rw");
			FileChannel toFC = transferToFile.getChannel();
			long position = 0;
			long count = fromFC.size();
			System.out.println(count);
			toFC.transferFrom(fromFC, position, count);
		} catch (Exception e) {
			// TODO: handle exception
		} finally {
			try {
				if (transferFromFile != null) {
					transferFromFile.close();
				}
				if (transferToFile != null) {
					transferToFile.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

}
